﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;
using System.Collections.Generic;

public partial class Manage_Cms_TemplateFileListBackUp : System.Web.UI.Page
{
    
    protected ManageErrMsg nsb = new ManageErrMsg();
    //获取请求过来的信息
    protected KeRui.BLL.SysConfig bllSysConfig = new KeRui.BLL.SysConfig();
    protected KeRui.Model.SysConfig modelSysConfig;

    public List<KeRui.Model.CmsTemplateFileBackUp> list;

    protected KeRui.BLL.CmsTemplateFile bllCmsTemplateFile = new KeRui.BLL.CmsTemplateFile();
    protected KeRui.Model.CmsTemplateFile modelCmsTemplateFile = new KeRui.Model.CmsTemplateFile();

    private KeRui.BLL.CmsTemplateFileBackUp bllCmsTemplateFileBackUp = new KeRui.BLL.CmsTemplateFileBackUp();
    private KeRui.Model.CmsTemplateFileBackUp modelCmsTemplateFileBackUp = new KeRui.Model.CmsTemplateFileBackUp();

    #region 分页
    public int PageSize = 10;                               //每页数量
    public int PageIndex = PageRequest.GetInt("page", 1);   //请求的页码
    public int PageCS = PageRequest.GetInt("cs", -1);       //记录总数
    public int PageCount = 0;                               //总页数
    public string PageShow = "";                            //分页显示
    #endregion 分页

    protected int SiteID = -1;
    protected int FileID = -1;

    protected void Page_Load(object sender, EventArgs e)
    {
        ManageHelper.CheckAdminLogin();//登陆判断 

        SiteID = PageRequest.GetInt("siteID", -1);
        FileID = PageRequest.GetInt("ID", -1);

        string url = "siteID=" + SiteID + "&ID=" + FileID;

        switch (ManageHelper.PageAct())
        {
            case "reduce":
                Reduce();
                break;
            case "view":
                View();
                break;
            default:
                modelSysConfig = new KeRui.Model.SysConfig();
                if (modelSysConfig == null)
                {
                    nsb.AddErr("Error。"); nsb.ChkErr();
                }
                break;
        }

        list = bllCmsTemplateFileBackUp.GetList(" FileID=" + FileID, PageSize, PageIndex);

        //总数
        if (PageCS == -1)
            PageCS = bllCmsTemplateFileBackUp.GetCount(" FileID=" + FileID);
        //总页数
        if (PageCS % PageSize == 0)
            PageCount = PageCS / PageSize;
        else
            PageCount = PageCS / PageSize + 1;
        //分页显示
        PageShow = ManageHelper.showSplitPage("TemplateFileListBackUp.aspx?cs=" + PageCS.ToString() + "&page={0}&" + url, PageIndex, PageSize, PageCS);
    }

    #region 还原
    private void Reduce()
    {
        ManageHelper.CheckAdminPower("site_templateedit_" + SiteID);//权限
        //------------------
        int ID = PageRequest.GetInt("ID", -1);
        if (ID == -1)
        {
            nsb.AddErr("error：传入参数有误。"); nsb.ChkErr();
        }
        modelCmsTemplateFileBackUp = bllCmsTemplateFileBackUp.GetModel(ID);
        modelCmsTemplateFile = bllCmsTemplateFile.GetModel(modelCmsTemplateFileBackUp.FileID);

        modelCmsTemplateFile.FileUpdateInterval = modelCmsTemplateFileBackUp.FileUpdateInterval;
        modelCmsTemplateFile.FileContent = modelCmsTemplateFileBackUp.FileContent;
        modelCmsTemplateFile.TemplateID = modelCmsTemplateFileBackUp.TemplateID;
        modelCmsTemplateFile.FileType = modelCmsTemplateFileBackUp.FileType;
        modelCmsTemplateFile.IsTop = modelCmsTemplateFileBackUp.IsTop;

        FileObj.WriteFileNoSign(modelCmsTemplateFile.FilePath, modelCmsTemplateFile.FileContent);
        bllCmsTemplateFile.Update(modelCmsTemplateFile);

        ManageHelper.AddLog("site_templateedit_" + SiteID, "修改了“" + modelCmsTemplateFile.FileName + "”模板文件。");
        Response.Write("<script type=\"text/javascript\">window.parent.location.href='TemplateFileList.aspx?siteid=" + SiteID + "&TemplateID=" + modelCmsTemplateFileBackUp.TemplateID + "&sucmsg=恭喜。还原成功。'</script>");
    }
    #endregion

    #region 预览
    private void View()
    {
        int ID = PageRequest.GetInt("ID", -1);
        modelCmsTemplateFileBackUp = bllCmsTemplateFileBackUp.GetModel(ID);
        modelCmsTemplateFileBackUp.FileContent = modelCmsTemplateFileBackUp.FileContent;//NEED处理
        Response.Write(modelCmsTemplateFileBackUp.FileContent);
        Response.End();
    }
    #endregion
}
